
import Search from '@/pages/Search/index';
import Login from '@/pages/Login/index';
import Register from '@/pages/Register/index';
import Detail from "@/pages/Detail/index";
import AddCartSuccess from '@/pages/AddCartSuccess';
import ShopCart from '@/pages/ShopCart';
import Trade from '@/pages/Trade';
import Pay from '@/pages/Pay';
import PaySuccess from '@/pages/PaySuccess';
import Center from '@/pages/Center';
import myOrder from '@/pages/Center/myOrder';
import groupOrder from '@/pages/Center/groupOrder';
export default [
    //订单页面
    {
        path: '/Center',
        component: Center,
        meta: { isShow: true },
        children: [
            //我的订单
            {
                path: 'myOrder',
                component: myOrder
            },
            //团队订单
            {
                path: 'groupOrder',
                component: groupOrder
            },
            {
                path: '/Center',
                redirect: '/Center/myOrder',
            }
        ]
    },

    //支付成功页面
    {
        path: '/PaySuccess',
        component: PaySuccess,
        meta: { isShow: true },
        //独享路由守卫
        beforeEnter: (to, from, next) => {
            let b = to.path == '/PaySuccess' && from.path == '/'//刷新网页的路由变化
            //支付页面必须从提交订单路由来 /Pay    刷新网页(相当于从/PaySuccess到/PaySuccess)  /PaySuccess
            if (from.path == '/Pay' || b) {
                next()
            } else {
                next(false)
            }
        }
    },
    //支付页面
    {
        name: 'pay',
        path: '/Pay',
        component: Pay,
        meta: { isShow: true },
        //独享路由守卫
        beforeEnter: (to, from, next) => {
            let b = to.path == '/Pay' && from.path == '/'//刷新网页的路由变化
            //支付页面必须从提交订单路由来 /Trade    刷新网页(相当于从/Pay到/Pay)  /Pay
            if (from.path == '/Trade' || b) {
                next()
            } else {
                next(false)
            }
        }
    },
    //订单页面
    {
        name: 'trade',
        path: '/Trade',
        component: Trade,
        meta: { isShow: true },
        //独享路由守卫
        beforeEnter: (to, from, next) => {
            let b = to.path == '/Trade' && from.path == '/'//刷新网页的路由变化
            //提交订单页面必须从购物车路由来 /ShopCart    刷新网页(相当于从Trade到Trade)  /Trade
            if (from.path == '/ShopCart' || b) {
                next()
            } else {
                next(false)
            }
        }
    },
    //购物车页面
    {
        name: 'shopCart',
        path: '/ShopCart',
        component: ShopCart,
        meta: { isShow: true }
    },
    //购物车添加成功页面
    {
        name: 'addCartSuccess',
        path: '/AddCartSuccess/:skuNum?',
        component: AddCartSuccess,
        meta: { isShow: true }
    },
    //商品详情页面
    {
        path: '/detail/:skuId?',
        component: Detail,
        meta: { isShow: true }
    },
    {
        path: '/home',
        component: () => import('@/pages/Home/index'),//路由懒加载
        meta: { isShow: true }
    },
    {
        name: "search",
        //?表示在url  /search后面可以不携带参数  params参数可以为空
        path: '/search/:keyword?',
        component: Search,
        meta: { isShow: true },
    },
    {
        path: '/Login',
        component: Login,
        meta: { isShow: false }
    },
    {
        path: '/register',
        component: Register,
        meta: { isShow: false }
    },
    {
        path: '*',
        redirect: "/home"//重点位 用户一打开就进入首页路由  

    }
]
